/* 
 * File:   printgraph.h
 * Author: asicherer
 *
 * Created on October 22, 2008, 10:20 AM
 */

#ifndef _PRINTGRAPH_H
#define	_PRINTGRAPH_H

#include <iostream>

/// debugging function to display scenegraph
void printSceneGraph(osg::Node *pNode, int level)
{
  int indent = 2;

  if (!pNode) return;

  std::string c = pNode->className();
  std::string n = pNode->getName();
  for (int i = 0; i < level; ++i)
  {
      std::cout << " ";
  }
  std::cout << pNode << " " << c << " (" << n << ")" << std::endl;

  osg::Geode *pGeode = dynamic_cast<osg::Geode*>(pNode);
  if (pGeode)
  {
    for (unsigned int i=0; i<pGeode->getNumDrawables(); i++)
    {
      osg::Drawable *pDrawable = pGeode->getDrawable(i);
      for (int i = 0; i <= level; ++i)
      {
          std::cout << " ";
      }
      std::cout << pDrawable << " " << pDrawable->className() << std::endl;
    }
  }
  
  // recursive call
  osg::Group *pGroup = dynamic_cast<osg::Group*>(pNode);
  if (pGroup)
  {
    for (unsigned int i=0; i<pGroup->getNumChildren(); i++)
    {
      printSceneGraph(pGroup->getChild(i), level+1);
    }
  }
}



#endif	/* _PRINTGRAPH_H */

